<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 意见"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId"  stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="反馈人" prop="userName" width="120">
					<template #default="scope">
						<div style="position: relative;" v-if="scope.row.userName!='' && scope.row.userName!=null">
							<el-avatar :src="scope.row.avatar" size="small"></el-avatar>
							<span style="position: absolute;margin-left: 10px">{{scope.row.userName}}</span>
						</div>
						<div v-else>匿名</div>
					</template>
				</el-table-column>
				<el-table-column label="意见标题" prop="title" width="250" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="意见类型" prop="mailTypeName" width="100"></el-table-column>
				<el-table-column label="意见内容" prop="remark" width="500" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="接收状态" prop="status" width="100">
					<template #default="scope">
						<el-tag v-if="scope.row.status=='1'" type="success">已接收</el-tag>
						<el-tag v-else type="warning">未接收</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="100">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<mail-details v-if="dialog.detailsSave" ref="saveDetailsDialog" @success="handleSaveSuccess" @closed="dialog.detailsSave=false"></mail-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import saveDialog from './save'
import MailDetails from "@/views/info/leadermailbox/mailDetails";
export default {
	name: ' Leader Mail Box Record',
	components: {
		MailDetails,
		saveDialog,
		scSelectFilter
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "意见类型",
					key: "mailType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "查收状态",
					key: "status",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					},{
						value: '0',
						label: '未接收'
					},{
						value: '1',
						label: '已接收'
					}],
				}
			],
			apiObj: this.$API.info.LeaderMailbox.getLeaderMailBoxList,
			search: {
				status:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode();
	},
	methods: {
		async getSysDicByCode()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'leaderMailType'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//查看
		table_show(row) {
			this.$nextTick(() => {
				this.dialog.detailsSave = true
				this.$nextTick(() => {
					this.$refs.saveDetailsDialog.open("rec").setData(row);
				})
			})
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data){
			this.$refs.table.upData(data)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
